(function(){
	'use strict';
	angular.module('services.workOrderData.useAndHandle',[])
	.factory('useAndHandleFactory',useAndHandleFactory);
	function useAndHandleFactory(Restangular,CoreService){
		return {
			pageBindData: pageBindData,
			query: query,
			fmtSendData: fmtSendData,
			getTitle: getTitle
		};
		function query(params,callback){
			Restangular.all('sas/workOrderData/useAndHandleCondition/query').post(params).then(callback);
		}

		function pageBindData(){
			var year = new Date().getFullYear();
      var month = new Date().getMonth();
			return {
				startTime: new Date(year,month-6),
        endTime: new Date(year,month-1),
        statisticsType: '1',
        changeTypeCode: ''
			}
		}
		//格式化需求发送给后端的字段
    function fmtSendData(sendData){
      return {
        startTime: CoreService.dateFormat(sendData.startTime, 'yyyy-MM-dd'),
        endTime: CoreService.dateFormat(sendData.endTime, 'yyyy-MM-dd'),
        statisticsType: sendData.statisticsType,
        changeTypeCode: sendData.changeTypeCode,
        timeType: '3'
      };
    }
    function getTitle(code,time,statisticsTypeName,workOrderTypeName){
			var title ='';
			var name = '提单数据趋势';
			switch(code){
				case 't1001':
					title =  time + statisticsTypeName + name;
					break;
				case '5007':
				case '305565':
					title =  time + '各科室' + statisticsTypeName + name;
					break;
				case '24807':
				case '15601':
					title =  time + '各系统' + statisticsTypeName + name;
					break;
				case 't1006':
					title =  time + '各科室' + workOrderTypeName + '解决率趋势';
					break;
				case 't1007':
					title =  time + '各科室' + workOrderTypeName + '及时处理率趋势';
					break;
			}
			return title;
		}
	}
})();